being.web package¶
Being web GUI. Web server, API and web socket. JS front-end can be found in static folder.
being.web.api: API route definitions.being.web.server: Web server instance.being.web.web_socket: All things web socket.
Data serialization can be found in being.serialization.
Submodules¶
being.web.api module¶
API calls and routes for communication with front-end.
- messageify(obj) collections.OrderedDict[source]¶
Serialize being objects and wrap them inside a message object. In order to differentiate between the message about an object and the object itself.
- Parameters
obj – Some being object to send.
- Returns
JSON serializable OrderedDict.
- content_routes(content: being.content.Content) aiohttp.web_routedef.RouteTableDef[source]¶
Controller for content model. Build Rest API routes. Wrap content instance in API.
- Parameters
content – Being content instance.
- Returns
Routes table for API app.
- serialize_elk_graph(being: being.being.Being, skipParamBlocks: bool = True)[source]¶
Serialize being blocks to ELK style graph dict serialization. Used in UI for block network visualization.
- Parameters
being – Being instance.
skipParamBlocks (optional) – If to skip all Params blocks to reduce clutter. True by default.
- Returns
Dict based graph representation compatible with ELK JS lib.
Note
Why yet another graph serialization? Because of edge connection type and double edges. These things do not matter for the execOrder, but they do for the block diagram.
- being_routes(being: being.being.Being) aiohttp.web_routedef.RouteTableDef[source]¶
API routes for being object.
- Parameters
being – Being instance to wrap up in API.
- Returns
Routes table for API app.
- behavior_routes(behaviors) aiohttp.web_routedef.RouteTableDef[source]¶
API routes for being behaviors.
- Parameters
behaviors – All behaviors.
- Returns
Routes table for API app.
- motion_player_routes(motionPlayers, behaviors) aiohttp.web_routedef.RouteTableDef[source]¶
API routes for motion players. Also needs to know about behaviors. To pause them on some actions.
- Parameters
motionPlayers – All motion players.
behaviors – All behaviors.
- Returns
Routes table for API app.
- motor_routes(being) aiohttp.web_routedef.RouteTableDef[source]¶
API routes for motors. Also needs to know about behaviors. To pause them on some actions.
- Parameters
being – Main being application instance.
- Returns
Routes table for API app.
being.web.responses module¶
Some web response short forms.
being.web.server module¶
Web server back end.
- wire_being_loggers_to_web_socket(ws: being.web.web_socket.WebSocket)[source]¶
Add custom logging handler to all being loggers which emits log records via web socket to the front end.
- Parameters
ws – Web socket.
- patch_sensor_to_web_socket(sensor, ws: being.web.web_socket.WebSocket)[source]¶
Route sensor output messages to web socket.
- init_api(being: being.being.Being, ws: being.web.web_socket.WebSocket) aiohttp.web_app.Application[source]¶
Initialize and setup sub-app for API. Some actions affect other components which get updated via the web socket.
- Parameters
being – Being instance.
ws – Web socket.
- Returns
aiohttp API sub.application.
- init_web_server(being: being.being.Being, ws: being.web.web_socket.WebSocket) aiohttp.web_app.Application[source]¶
Initialize aiohttp web server application and setup some routes.
- Parameters
being – Being instance.
ws – Web socket
- Returns
Application instance.
- Return type
app
being.web.web_socket module¶
Web socket proxy.
- class WebSocket[source]¶
Bases:
objectWebSocket connections. Interfaces with aiohttp web socket requests. Can hold multiple open web socket connections simultaneously. Also has a message queue / broker functionality to send messages from non-asyncio world.
- sockets¶
Active web socket connections.
- Type
sockets
- queue¶
Message queue for synchronous senders.
- Type
queue
- async send_json(data)[source]¶
Send data as JSON to all connected web sockets.
- Parameters
data – Data to send as JSON.
- send_json_buffered(data)[source]¶
Synchronous send_json(). Data goes into message queue and send at a later stage (if broker task is running).
- Parameters
data – Data to send as JSON.
- async handle_new_connection(request) aiohttp.web_ws.WebSocketResponse[source]¶
Aiohttp new web socket connection request handler.
- async close_all_connections(app: Optional[aiohttp.web_app.Application] = None)[source]¶
Close all web sockets. Can be used with app.on_shutdown() / app.on_cleanup().
- async broker_task()[source]¶
Message broker task. Takes messages from queue and sends them over all open web socket connections.